<?php
namespace app\admin\controller;
use app\common\entity\BackResult;
use app\common\service\UploadService;
use app\Request;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/10/12 0012
 * Time: 15:50
 */
class Upload{
    //小程序类型 商家上传的图片
    protected  $type = 1;
    public function upload(Request $request){
        $file = $request->file('file');

        try{
            $service = new UploadService();
            $data = $service->upload($file);
        }catch (\Exception $e){
            return BackResult::error($e->getTrace());
        }
        return BackResult::success($data);
    }


    /**
     * @param Request $request
     * @return \think\Response
     */
    public function images(Request $request){
        $page = $request->get("page",1);
        $pageSize = $request->get("pageSize", 10);
        $service = new UploadService();
        $images = $service->images($this->type,$page,$pageSize);
        return BackResult::success($images);
    }

    public function delete(Request $request){
//        $id = $request->get('id');
//        $service = new UploadService();
//        try{
//            $service->delete($id,$this->shop['id'],$this->type);
//        }catch ( \Exception $e ){
//            $this->error($e->getMessage());
//        }
//        $this->success("删除成功");
    }
}